package net.ibizsys.eclipse.studio.tree;

import java.util.List;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

/**
 * 树数据提供对象
 * 
 * @author <a href='http://www.weibo.com/xjtoo' target='_blank'>Enmaai</a>
 */
public class IBizTreeContentProvider implements IStructuredContentProvider, ITreeContentProvider
{
	@Override
	public Object[] getElements(Object element)
	{
		if (element instanceof List)
		{
			return ((List<?>) element).toArray();
		}
		return new Object[0];
	}

	@Override
	public Object[] getChildren(Object element)
	{
		if (element instanceof IBizTreeNode)
		{
			IBizTreeNode node = (IBizTreeNode) element;

			return node.getChildren().toArray();
		}
		return new Object[0];
	}

	@Override
	public boolean hasChildren(Object element)
	{
		if (element instanceof IBizTreeNode)
		{
			IBizTreeNode node = (IBizTreeNode) element;

			return node.getChildren().size() > 0;
		}
		return false;
	}

	@Override
	public Object getParent(Object element)
	{
		return null;
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldValue, Object newValue)
	{

	}

	@Override
	public void dispose()
	{

	}
}